<?php namespace Admin\Controller;
class TypeattrController extends CommonController{
	protected $db;
	public function __construct(){
		$this->db = new \Common\Model\Typeattr;
		parent::__construct();
	}
	public function index(){
		$type_id = $_GET['type_id'];
		$typeattrdata = $this->db->where("ta_type_id",$type_id)->get();
		View::with("typeattrdata",$typeattrdata);
		View::make();
	}
	//添加属性
	public function add(){
		if(IS_POST){
			if(!$this->db->store()){
				View::error($this->db->getError());
			}else{
				View::success("添加成功",U('Typeattr/index',array('type_id'=>$_GET['type_id'])));
			}
		}
		View::make();
	}
	//编辑属性
	public function edit(){
		 $ta_id = $_GET['ta_id'];
		$olddata = $this->db->where("ta_id","$ta_id")->first();
		View::with("olddata",$olddata);
			if(IS_POST){
			if(!$this->db->edit()){
				View::error($this->db->getError());
			}else{
				View::success("编辑成功",U('Typeattr/index',array('type_id'=>$_GET['type_id'])));
			}
		}
		View::make();
	}
	//删除属性
	    public function del(){
	    	 $ta_id = $_GET['ta_id'];
			 $this->db->where("ta_id","$ta_id")->delete();
			 View::success("删除成功",U('Typeattr/index',array('type_id'=>$_GET['type_id'])));
	    }
}